package process;

import java.sql.*;


public final class DBConnectionPool {
    private static DBConnectionPool instance; 

// ����� ������ ����Ÿ���̽� �������� �����մϴ�.
	private String driver="org.gjt.mm.mysql.Driver";
    private String url="jdbc:mysql://210.118.74.203:3306/hack?useUnicode=true&useUnicode=true&characterEncoding=utf8";
    private String user="root";
    private String password="admin";
    private Connection conn;

	public static synchronized DBConnectionPool getInstance() {
        if (instance == null) {
		    instance=new DBConnectionPool();
        }
        return instance;
    }

    private DBConnectionPool() {  
		driverLoading(this.driver,this.url,this.user,this.password);
	}


	public Connection getConnetion() throws SQLException{
		conn=DriverManager.getConnection(url,user,password);
		return conn;
	}

/** 
	DB ������ ���� ���������� JDBC ����̹��� �ε��ϴ� �޼ҵ��Դϴ�.
*/
    public void driverLoading(String driver,String url, String user, String password){
    	System.out.println("driverLoading:"+driver+":"+url+":"+user+":"+password);
		if(driver !=null) this.driver=driver;
		if(url !=null) this.url=url;
		if(user != null) this.user=user;
		if(password != null) this.password=password;
		try{
			Class.forName(driver);
			conn=DriverManager.getConnection(url,user,password);
	    } catch (Exception e){
		    System.out.println("Driver Loading Error  : \n");
			e.printStackTrace();
	    }
    }
}